import CryptoJS from './crypto-js/crypto-js.js'

const EN_KEY = "/R.m6i*_u7($i,l-@.;P%z5~0+)U+Z=3"
const DE_KEY = "/R.m6i*_u7($i,l-@.;P%z5~0+)U+Z=3"

// 加密数据
function encryption(data) {
	var srcs = CryptoJS.CryptoJS.enc.Utf8.parse(data);
	var key = CryptoJS.CryptoJS.enc.Utf8.parse(EN_KEY);
	var encrypted = CryptoJS.CryptoJS.AES.encrypt(srcs, key, {
	    mode: CryptoJS.CryptoJS.mode.ECB,
	    padding: CryptoJS.CryptoJS.pad.Pkcs7
	});
	//返回大写十六进制加密结果
	return encrypted.toString();
};

// 解密数据
function deciphering(data) {
	var key = CryptoJS.CryptoJS.enc.Utf8.parse(DE_KEY);
	    //mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7
	var decrypt = CryptoJS.CryptoJS.AES.decrypt(data, key, {
	    mode: CryptoJS.CryptoJS.mode.ECB,
	    padding: CryptoJS.CryptoJS.pad.Pkcs7
	});
	var decryptedStr = decrypt.toString(CryptoJS.CryptoJS.enc.Utf8);
	return decryptedStr.toString();
};

export default {
	encryption,
	deciphering
}
